package com.kepler.social.web.common;

import com.kepler.social.common.constants.BusinessState;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpResult<T> {

    private int code;

    private String message;

    private T data;

    public HttpResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public HttpResult(BusinessState businessState) {
        this(businessState.code, businessState.message);
        this.data = data;
    }

    public static <T> HttpResult<T> success() {
        return new HttpResult(BusinessState.OK);
    }

    public static <T> HttpResult<T> success(T data) {
        HttpResult<T> result = new HttpResult(BusinessState.OK);
        result.setData(data);
        return result;
    }

    public static <T> HttpResult<T> success(String message, T data) {
        return new HttpResult(BusinessState.OK.code, message, data);
    }
}
